package com.insight.modules.system.model;

import lombok.Data;
import com.insight.modules.system.entity.SysPermission;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 树形列表用到
 */
@Data
public class TreeModel implements Serializable {

	private static final long serialVersionUID = 4013193970046502756L;

	private String key;

	private String title;

	private String slotTitle;

	private Boolean isLeaf;

	private String icon;

	private Integer ruleFlag;

	private Integer platformType;

	private Map<String, String> scopedSlots;

	private List<TreeModel> children;

	public TreeModel() {

	}

	public TreeModel(SysPermission permission) {
		this.key = permission.getId();
		this.icon = permission.getIcon();
		this.parentId = permission.getParentId();
		this.title = permission.getName();
		this.slotTitle = permission.getName();
		this.value = permission.getId();
		this.isLeaf = permission.isLeaf();
		this.label = permission.getName();
		this.platformType = permission.getPlatformType();
		if (!permission.isLeaf()) {
			this.children = new ArrayList<TreeModel>();
		}
	}

	public TreeModel(String key, String parentId, String slotTitle, Integer ruleFlag, boolean isLeaf) {
		this.key = key;
		this.parentId = parentId;
		this.ruleFlag = ruleFlag;
		this.slotTitle = slotTitle;
		Map<String, String> map = new HashMap<String, String>();
		map.put("title", "hasDatarule");
		this.scopedSlots = map;
		this.isLeaf = isLeaf;
		this.value = key;
//		if (!isLeaf) {
//			this.children = new ArrayList<TreeModel>();
//		}
	}

	private String parentId;

	private String label;

	private String value;

}
